from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from .models import UserProfile, UserToken


@admin.register(UserProfile)
class UserProfileAdmin(BaseUserAdmin):
    model = UserProfile
    list_display = ('id', 'is_superuser', 'is_staff', 'is_active', 'last_login', 'data_joined')
    list_filter = ('is_superuser', 'is_staff', 'is_active')
    ordering = ('id',)
    search_fields = ('id',)

    fieldsets = (
        (None, {'fields': ('id', 'password')}),
        ('Permissions', {'fields': ('is_superuser', 'is_staff', 'is_active', 'groups', 'user_permissions')}),
        ('Important dates', {'fields': ('last_login', 'data_joined')}),
    )
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('id', 'password1', 'password2', 'is_superuser', 'is_staff', 'is_active')
        }),
    )
    readonly_fields = ('data_joined',)


@admin.register(UserToken)
class UserTokenAdmin(admin.ModelAdmin):
    list_display = ('user', 'token', 'created_at')
    search_fields = ('user__id', 'token')
    readonly_fields = ('token', 'created_at')

